{extend name="platform/base" /}
{block name="resources"/}
<style>
.col-md-2 {
    line-height: 35px;
}
</style>
{/block}
{block name="main"}
<section class="panel panel-default">
	<header class="panel-heading text-right bg-light">
		<ul class="nav nav-tabs pull-left">
			<li class="active"><a href="#base" data-toggle="tab">店铺信息</a></li>
		</ul>
		<span class="hidden-sm">添加店铺</span>
	</header>
	<div class="panel-body">
		<div class="tab-content">
			<div class="tab-pane fade active in" id="base">
					<div class="panel-body">
						<div class="form-horizontal">
						
							<div class="form-group">
								<label class="col-sm-2 control-label"><span class="color-red">*</span>会员账号</label>
								<div class="col-md-2">
									<input type="text" class="form-control" id="shop_user_account" value="" placeholder="请输入会员账号" onkeydown="error_hide()">
								</div>
								<p class="error">会员账号不能为空！</p>
							</div>
							<div class="line line-dashed line-lg pull-in"></div>
							
							<div class="form-group">
								<label class="col-sm-2 control-label"><span class="color-red">*</span>会员密码</label>
								<div class="col-md-2">
									<input type="password" class="form-control" id="shop_user_pwd" value="" placeholder="请输入会员密码" onkeydown="error_hide()">
								</div>
								<p class="error">会员密码不能为空！</p>
							</div>
							<div class="line line-dashed line-lg pull-in"></div>
							
							<div class="form-group">
								<label class="col-sm-2 control-label"><span class="color-red">*</span>店铺名称</label>
								<div class="col-md-2">
									<input type="text" class="form-control" id="shop_name"
										value="" placeholder="请输入店铺名称" onkeydown="error_hide()">
								</div>
								<p class="error">店铺名称不能为空！</p>
							</div>
							
							
							
							
							
							
							
							<div class="line line-dashed line-lg pull-in"></div>
							<div class="form-group">
								<label class="col-sm-2 control-label">所属分类</label>
								<div class="col-md-4">
									<select id="shop_group_id" name="account"
										class="form-control m-b"> 
										{foreach name="group_list" item="vg"}
											<option value="{$vg['shop_group_id']}">{$vg['group_name']}</option>
										{/foreach}
									</select>
								</div>
							</div>
							
							<div class="line line-dashed line-lg pull-in"></div>
							<div class="form-group">
								<label class="col-sm-2 control-label">所属等级</label>
								<div class="col-md-4">
									<select id="shop_type" name="account" class="form-control m-b" onchange='change_type()'>
										{foreach name="type_list" item="vt"}
											<option value="{$vt['instance_typeid']}" guid="{$vt['instance_typeid']}">{$vt['type_name']}</option>
										{/foreach}
									</select>
								</div>
							</div>
							<div class="line line-dashed line-lg pull-in"></div>
							<div class="form-group">
								<label class="col-sm-2 control-label"><span class="color-red">*</span>年费(元)</label>
								<div class="col-md-2">
									<input type="num" class="form-control" id="fee_year"
										value="0" placeholder="请输入年费" onkeydown="error_hide()">
								</div>
								<p class="error">年费不能为空！</p>
							</div>
							
							<div class="line line-dashed line-lg pull-in"></div>
							<div class="form-group">
								<label class="col-sm-2 control-label">账户类型</label>
								<div class="col-md-4">
									<select id="bank_type" name="bank_type" class="form-control m-b"> 
										<option value="1">银行卡</option>
										<option value="2">支付宝</option>
									</select>
								</div>
							</div>
							
							<div class="form-group" id="branch_bank">
								<label class="col-sm-2 control-label"><span class="color-red">*</span>支行信息</label>
								<div class="col-md-2">
									<input type="text" class="form-control" id="bank_account_name" value="" placeholder="请输入支行信息" onkeydown="error_hide()">
								</div>
								<p class="error">支行信息不能为空！</p>
							</div>
							
							<div class="form-group">
								<label class="col-sm-2 control-label"><span class="color-red">*</span>账号信息</label>
								<div class="col-md-2">
									<input type="text" class="form-control" id="bank_account_number" value="" placeholder="请输入账号信息" onkeydown="error_hide()">
								</div>
								<p class="error">账号信息不能为空！</p>
							</div>
							
							<div class="form-group">
								<label class="col-sm-2 control-label"><span class="color-red">*</span>联系姓名</label>
								<div class="col-md-2">
									<input type="text" class="form-control" id="bank_real_name"	value="" placeholder="请输入联系姓名" onkeydown="error_hide()">
								</div>
								<p class="error">联系姓名不能为空！</p>
							</div>
							
							
							<div class="form-group">
								<label class="col-sm-2 control-label"><span class="color-red">*</span>联系电话</label>
								<div class="col-md-2">
									<input type="text" class="form-control" id="bank_mobile"	value="" placeholder="请输入联系电话" onkeydown="error_hide()">
								</div>
								<p class="error">联系电话不能为空！</p>
							</div>
							
							<div class="form-group">
								<div class="col-sm-4 col-sm-offset-2">
									<a href="javascript:void(0);" onclick="addShopAjax()" class="btn btn-primary">保存</a>
								</div>
							</div>
						</div>
					</div>
			</div>

		</div>
	</div>
	
</section>

<script type="text/javascript"> 
	//选择支付账号类型
	$(function(){
			$("select#bank_type").change(function(){
				var bank_type = $("#bank_type").val();
				if(bank_type == 1){
					$("#branch_bank").show();
				}
				else
				{
					$("#branch_bank").hide();
					$("#bank_account_name").val('');
				}
				
			});
		});
	//添加店铺
	function addShopAjax() {
		
		var user_account = $("#shop_user_account").val();
		var user_pwd = $("#shop_user_pwd").val();
		var shop_name = $("#shop_name").val();
		var shop_group_id = $("#shop_group_id").val();
		var shop_type = $("#shop_type").val();
		
		
		//结算信息
		var bank_type = $("#bank_type").val();
		var bank_account_name = $("#bank_account_name").val();
		var bank_account_number = $("#bank_account_number").val();
		var bank_real_name = $("#bank_real_name").val();
		var bank_mobile = $("#bank_mobile").val();
		
		if(user_account == ''){
			$("#shop_user_account").focus().parent().next().show();
			return false;
		}
		if(user_pwd == ''){
			$("#shop_user_pwd").focus().parent().next().text('会员密码不能为空！');
			$("#shop_user_pwd").focus().parent().next().show();
			return false;
		}else
		if(user_pwd.length < 5 || user_pwd.length > 16){
			$("#shop_user_pwd").focus().parent().next().text('会员密码不能少于5或大于16位！');
			$("#shop_user_pwd").focus().parent().next().show();
			return false;
		}
		if(shop_name == ''){
			$("#shop_shop_name").focus().parent().next().show();
			return false;
		}
		
		if(bank_type == 1){
			if(bank_account_name == ''){
				$("#bank_account_name").focus().parent().next().show();
				return false;
			}
		}
	

		if(bank_account_number == ''){
			$("#bank_account_number").focus().parent().next().show();
			return false;
		}


		if(bank_real_name == ''){
			$("#bank_real_name").focus().parent().next().show();
			return false;
		}
		
		if(bank_mobile == ''){
			$("#bank_mobile").focus().parent().next().show();
			return false;
		}
		
		$.ajax({
			type : "post",
			url : "{:__URL('PLATFORM_MAIN/shop/addPlatformShop')}",
			data : {
				'shop_name' : shop_name,
				'shop_group_id' : shop_group_id,
				'shop_type' : shop_type,
				'user_account' : user_account,
				'user_pwd' : user_pwd,
				
				'bank_real_name' : bank_real_name,
				'bank_mobile' : bank_mobile,
				'bank_type' : bank_type,
				'bank_account_name' : bank_account_name,
				'bank_account_number' : bank_account_number
			},
			async : true,
			success : function(data) {
				if (data["code"] > 0) {
					showMessage('success', "添加成功",'{:__URL("PLATFORM_MAIN/Shop/shoplist")}');
				} else {
					showMessage('error', data['message']);
				}
			}
		});
	}
</script>
{/block}
